

function template  () {
    
    var $_template = this;
    
    $_template.classExists = function (id) {
        
           var found = false;
            
            for (var i=0;i<document.styleSheets.length;i++)  {
                var mysheet=document.styleSheets[i]
                try {var myrules=mysheet.cssRules? mysheet.cssRules: mysheet.rules}
                catch (ERR) {}
                if (myrules != null) for (var r=0; r<myrules.length; r++){
                    if (myrules[r].selectorText != undefined) {                 
                        if (myrules[r].selectorText.toLowerCase() === id ) {
                            found = true;
                        } 
                    }         
                }
            }    
            return found;
    }
    
    $_template.initialize = function () {
        $(document).ready(function () {
            
            $("#menu_top a[href*=www2]").each(function () {
             
                //alert($(this).attr("href"))
                var href = $(this).attr("href");
                var new_href = href.replace("www2.peterborough.ac.uk",top.location.host);
                
               $(this).attr("href",new_href)
               
            });
            
            
            if (! $_template.classExists(".search_box_" + section )) {
                $("#search_box").addClass("search_box_main");
                $("#bg_left").addClass("bg_left_main");
            }
            
            $("#logo").each(function () {
                $(this).css({"border":"0px"})
                $(this).parent().css({"text-decoration":"none"})
            });
            
            if (! $_template.classExists("." + section + "_info_arrow")) {
                //console.log("." + section + "_info_arrow")
                $("#" + section + "_info_arrow").css({
                    height: "160px",
                    position: "absolute",
                    width: "165px"
                });
                
                $("#" + section + "_info_arrow img").css({
                    position: "absolute",
                    top: "15px"
                });
                
                $("#" + section + "_info").css ({
                    "background-color": "#66CCFF",
                    color: "#FFFFFF",
                    height: "160px",
                    padding: "10px",
                    position: "absolute",
                    width: "150px"
                })
                
                 $("#" + section + "_info h4").css({
                    "font-size": "20px",
                    "font-weight": "lighter",
                    "line-height": "22px",
                    margin: 0,
                    "padding-bottom": 0
                 });
                 
                 $("#" + section + "_info p").css({
                    "font-family": 'SommetRegular',
                    "font-size": "80%",
                    "line-height": "16px",
                    "margin-top": "7px"
                 });
                
                $("#section_banner").css({
                    bottom: 0,
                    "float": "left",
                    "font-size": "140%",
                    "font-weight": "lighter",
                    left: 0,
                    margin: 0,
                    padding: "10px",
                    "position": "absolute",
                    "background-color": "#66CCFF",
                    color: "#FFFFFF"
                });  
            }
            
 
           
            //Set the alt for images
            $(document).find("img").each(function (){
                //alert ($(this).attr("alt") + " " + $(this).attr("src"))
                if ($(this).attr("alt") == undefined) {
                    var filedata = $(this).attr("src").split("/");
                    var filename = filedata[filedata.length-1].split(".");
                    var alt = area + " " + section + " " + filename[0].replace(/_/g," ");
                    $(this).attr("alt",alt);
                }
            });
            
            
            if (area.toLowerCase() == "ucp") {
                $("#section_banner").css({"background-color": "#CC0000"});
                $("#" + section + "_info").css ({"background-color": "#CC0000"});
                $("#section_banner").html("Degree courses from UCP");
                
                var arrow_html = "<img class=\"section_head_arrow\" \
                                    src=\"/modules/section_header/templates/UCP/main/images/arrow_2.png\" \
                                    alt=\"courses UCP arrow 2\">"; 
                $("#section_banner").append(arrow_html);
                
                $("#courses_sub div:nth-child(3)").addClass("h_item")
                $("#courses_sub div:nth-child(3) a").css({"color":"white"});
                $("#courses_sub div:nth-child(3) img").css({"margin-left":"0px"});
                
                
                
            } else {
                switch (section) {
                    case  "school_leavers":
                      $("#section_banner").css({"background-color": "#FFDB00"});
                      $("#" + section + "_info").css ({"background-color": "#FFDB00"});
                      break;
                    case "apprenticeships":
                        $("#section_banner").css({"background-color": "#FF9933"});
                        $("#" + section + "_info").css ({"background-color": "#FF9933"});
                        break;
                    case "adult_learning":
                        $("#section_banner").css({"background-color": "#990099"});
                        $("#" + section + "_info").css ({"background-color": "#990099"})
                        break;          
                     case "business_employer":
                        $("#section_banner").css({"background-color": "#00CC99"});
                        $("#" + section + "_info").css ({"background-color": "#00CC99"})
                        break;                        
                     case "international":
                        $("#section_banner").css({"background-color": "#66CCFF"});
                        $("#" + section + "_info").css ({"background-color": "#66CCFF"})
                        break;                            
                  }
            }
            
            $(".intranet_vle").css({"margin-left": "30px"});
            
            if (section == "business_employer") $("#logo").attr("src","/images/prc_logo_bs.png");
            
            
            $("#content_text ul").css({
                "margin":"0px",
                "padding":"15px"
            })
            
            $("#submenu_holder > div > div > div").css("margin-right","3px")
            
            /*Set z-index for layers*/
            /*
            $("*").each(function () {
                var zindex = $(this).css("zIndex") == "auto" ? -1 : $(this).css("zIndex");
                if ( zindex > 0) {
                     $(this).parent().css("zIndex",zindex -1);
                }
               
            })
            */
        })
    }
    this.initialize();
    console.log(1)
}


